/**
 * Created by Administrator on 2016/12/5.
 */
app.controller('HomeController', function ( $ionicNavBarDelegate) {
    //$ionicNavBarDelegate.title('天气预报1')
    $ionicNavBarDelegate.align('left');
    //$ionicNavBarDelegate.showBackButton(false)
    //console.log($ionicHistory)
})
app.controller('WeatherController', function ($http, $scope, $ionicLoading) {
    var directions = ['北风', '东北风', '东风', '东南风', '南风', '西南风', '西风', '西北风']
    $scope.getDirection = function (deg) {
        if (deg > 338) {
            deg = 360 - deg
        }
        var index = Math.floor((deg + 22) / 45);
        return directions[index];
    }
    //没有加载成功时，显示加载图标
    //$ionicLoading.show();
    //$http.get('https://ionic-in-action-api.herokuapp.com/weather')
    //    .then(function(res){
    //        console.log(res.data);
    //        $scope.weather=res.data;
    //        $scope.weather.main.temp=(($scope.weather.main.temp-32)/1.8).toFixed(0)
    //        $scope.weather.main.temp_max=(($scope.weather.main.temp_max-32)/1.8).toFixed(0)
    //        $scope.weather.main.temp_min=(($scope.weather.main.temp_min-32)/1.8).toFixed(0)
    //        $ionicLoading.hide();
    //    })
    //    .catch(function(err){
    //        $ionicLoading.show({
    //            template:'请求天气数据失败',
    //            direction:3000
    //        })
    //    })
    $ionicLoading.show();
    $.getJSON('http://api.map.baidu.com/telematics/v3/weather?callback=?&location=%E9%83%91%E5%B7%9E%E5%B8%82&output=json&ak=iw5m2G7ayDow8ofDdDGVUMB3&mcode=com.BaiduWeather')
        .then(function(res)
        {
            console.log('百度天气的API')
            console.log(res.results[0].weather_data[1]);
            $scope.day=res.results[0].weather_data[0].date;
            $scope.weather=res.results[0].weather_data[0].weather;
            $scope.pm25=res.results[0].pm25;
            $scope.temp=res.results[0].weather_data[0].temperature;
            $scope.wind=res.results[0].weather_data[0].wind;
            $scope.tip=res.results[0].index[0];
            $scope.day2=res.results[0].weather_data[1];
            $scope.day3=res.results[0].weather_data[2];
            $scope.day4=res.results[0].weather_data[3];
            $ionicLoading.hide();
        }).catch(function(err){
                $ionicLoading.show({
                    template:'请求天气数据失败',
                    direction:3000
                })
            })


})

app.controller('NearbyController', function ($scope, $ionicHistory) {

})
app.controller('CheckController', function () {

})


